package xyz.bali16.module.sensitiveword.service;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.google.common.base.Preconditions;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import xyz.bali16.application.core.utils.TimeUtil;
import xyz.bali16.module.sensitiveword.entity.SensitiveWord;
import xyz.bali16.module.sensitiveword.mapper.SensitiveWordMapper;
import xyz.bali16.module.sensitiveword.model.SensitiveWordAddParam;
import xyz.bali16.module.sensitiveword.model.SensitiveWordPageParam;
import xyz.bali16.module.sensitiveword.model.SensitiveWordUpdateParam;


/**
 * @author bali2 on 9/3/2023.
 * @version 1.0
 */
@Service
public class SensitiveWordServiceImpl extends ServiceImpl<SensitiveWordMapper, SensitiveWord> implements SensitiveWordService {
    private final SensitiveWordMapper sensitiveWordMapper;

    public SensitiveWordServiceImpl(SensitiveWordMapper sensitiveWordMapper) {
        this.sensitiveWordMapper = sensitiveWordMapper;
    }

    @Override
    public IPage<SensitiveWord> getPage(SensitiveWordPageParam param) {
        IPage<?> page = new Page<>(param.getCurrent(), param.getSize());
        return this.baseMapper.getPage(page, param.getWord());
    }

    @Override
    public void addSensitiveWord(SensitiveWordAddParam param) throws Exception {
        Preconditions.checkNotNull(param, "SensitiveWordAddParam 参数不能为为空");
        SensitiveWord sensitiveWord = new SensitiveWord();
        BeanUtils.copyProperties(param, sensitiveWord);
        System.out.println(sensitiveWord);
        save(sensitiveWord);
    }

    @Override
    public void updateSensitiveWord(SensitiveWordUpdateParam param) throws Exception {
        Preconditions.checkNotNull(param, "SensitiveWordUpdateParam 参数不能为为空");
        SensitiveWord sensitiveWord = new SensitiveWord();
        BeanUtils.copyProperties(param, sensitiveWord);
        updateById(sensitiveWord);
    }

    @Override
    public void updateStatus(String sensitiveWordId, Integer status) throws Exception {
        Preconditions.checkNotNull(sensitiveWordId, "敏感词id不能为空");
        if (status == null) {
            return;
        }
        SensitiveWord sensitiveWord = new SensitiveWord();

        updateById(sensitiveWord);
    }

    @Override
    public void delete(String sensitiveWordId) throws Exception {
        if (sensitiveWordId == null) {
            return;
        }
        removeById(sensitiveWordId);

    }
}
